<template>
  <div>
    <div class="home-box box-3-list">
      <div class="center-box1">
        <div class="box-title-1">
          <img src="@/assets/image/5.webp" alt="">
          <div class="center">
            <p>恋爱论坛</p>
            <p>让每一份情感都真实无憾</p>
          </div>
        </div>
        <div class="box-2-nav">
          <a v-if="ForumList.length>0"
             href="javascript:void (0)"
             v-for="(item,index) in ForumList"
             :key="index"
             @click="changeValue(item)" class="box-item-length">
            <img class="img-left" :src="item.avatar" alt="">
            <div class="right-box">
                <div class="titles over-hide-1">
                  {{ item.title }}
                </div>
              <div class="time over-hide-3">
                {{ item.info }}
              </div>
              <p class="time"> {{ parseTime(item.createTime) || '暂无数据' }}</p>
              <a href="javascript:void (0)" class="btn-bot">
                查看详情
              </a>
            </div>
          </a>
          <div  v-if="ForumList.length<1" style="width: 100%;justify-content: center;display: flex">
            <el-empty></el-empty>
          </div>
        </div>
      </div>
    </div>

    <el-dialog :visible.sync="dialogVisible" width="850" :before-close="handleClose">
      <div class="dialog">
        <div class="dialog-left">
          <img :src="form.avatar" alt="">
        </div>
        <div class="dilog-right">
          <div class="title">
            {{form.title }}
          </div>
          <div class="time">
            发表于：{{ parseTime(form.createTime) || '暂无数据' }}
          </div>
          <div class="content">
            <span v-html="form.info"></span>
          </div>
          <div class="comment">
            <div class="item-nav-comment" v-for="(item,index) in  commentList" :key="index">
              <div class="item-comment" @click="getCommentLevel1(item)">
                <img class="avatar" :src="item.avatar" alt="">
                <div class="right-box">
                  <p>{{ item.username }}</p>
                  <p>{{ item.comment }}</p>
                </div>
              </div>
              <div class="children" v-for="(item1,index1) in item.childComment" :key="index1">
                <div class="item-comment">
                  <img class="avatar" :src="item1.avatar" alt="">
                  <div class="right-box">
                    <p>{{ item1.username }}</p>
                    <p>{{ item1.comment }}</p>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="input">
            <input type="text" v-model="message" :placeholder="commentUser ? '回复：'+commentUser :'请输入评论'">
            <a class="btn" @click="submitForm" href="javascript:void (0)">发表</a>
          </div>
        </div>
      </div>

    </el-dialog>

    <lz-footer></lz-footer>
  </div>
</template>

<script>

import {addComment, getAllUser, getDatEventList, getForumComment, getForumList} from "@/api/apiFox";
import {parseTime, removeHTMLTags, removeHtmlTags} from "../../utils";

export default {
  data(){
    return{
      dialogVisible:false,
      ForumList:[],
      commentList:[],
      levelForm:{},
      message:"",
      commentUser:"",
      form:{},
      queryParams:{
        pageSize:100,
        pageNum:1
      }
    }
  },
  methods:{
    parseTime,
    handleClose(){
      this.dialogVisible=false
    },

    getList(){
      getForumList(this.queryParams).then(res=>{
        if (res.totalCount>0){
          res.list.forEach(value=>{
            if (value.info){
              value.info = removeHTMLTags(value.info)
            }

          })
        }
        this.ForumList = res.list
      }).catch(err=>{
        console.log(err)
      })

    },
    getCommentLevel1(item){
      this.levelForm = item
      this.commentUser = item.username
    },
    closeCommentForm(){
      this.levelForm={}
      this.commentUser=""
      this.message = ""
      this.getCommentList(this.form)
    },
    submitForm(){
      if (this.message){
        if (this.levelForm.id){
          addComment({
            forumId:this.form.id,
            comment:this.message,
            level:2,
            commentId:this.levelForm.id
          }).then(res=>{
              this.$message.success('评论成功')
              this.closeCommentForm()
          }).catch(err=>{})
        }else{
          addComment({
            forumId:this.form.id,
            comment:this.message,
            level:1
          }).then(res=>{
            this.$message.success('评论成功')
            this.closeCommentForm()
          }).catch(err=>{})
        }

      }else{
        this.$message.error('请输入评论')
      }
    },

    changeValue(item){
      this.dialogVisible = true
      this.form = item
      this.getCommentList(item)
    },


    getCommentList(item){
      getForumComment({forumId:item.id}).then(res=>{
        console.log(res)
        this.commentList = res
      }).catch(err=>{})
    },

  },


  mounted() {
    this.getList()
  }
}
</script>

<style scoped lang="scss">
::v-deep(.el-dialog){
  border-radius: 30px;
}
.home-box{
  width: 100%;
  display: flex;
  justify-content: center;
  min-height: 80vh;
}
.box-nav-list{
  background: var(--navBgk);
  //height: 200px !important;
  min-height: 80vh;
  //margin-bottom: -200px;
  width: 100%;
  display: flex;
  justify-content: center;
  .home0-center{
    width: 1200px;
    padding-top: 120px;
    display: flex;
    height: 200px;
    justify-content: space-between;
    .item{
      width: 300px;
      height: 300px;
      text-align: center;
      .nav-box{
        width: 100%;
        height: 120px;
        border-radius: 50%;
        img{
          width: 100px;
          height: 100px;
          object-fit: cover;
        }
      }
      .title{
        font-size: 22px;
        color: var(--textColor);
        font-weight: 600;
      }
      .box-center{
        margin-top: 15px;
        font-size: 12px;
        color: var(--colorTip);
      }
    }
  }
}
.box-3-list{
  width: 100%;
  background: var(--navBgk);
  padding-bottom: 150px;
  padding-top: 45px;
  .center-box1{
    width: 1400px;
    .box-title-1{
      width: 100%;
      text-align: center;
      position: relative;
      .center{
        width: 100%;
        position: absolute;
        margin-top: -30px;
        p:nth-child(1){
          font-size: 28px;
          font-weight: 600;
          color: #fc476d;
        }
        p:nth-child(2){
          font-size: 12px;
          color: var(--colorTip);
        }
      }
    }
    .box-2-nav{
      width: 100%;
      margin-top: 100px;
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      .box-item{
        margin-bottom: 25px;
        width: 278px;
        min-height: 480px;
        background: var(--itemBgk);
        //border-radius: 10px;
        overflow: hidden;
        padding: 10px;
        box-sizing: border-box;
        box-shadow: rgba(149, 157, 165, 0.2) 0px 8px 24px;
        .image{
          width: 100%;
          height: 250px;
          object-fit: cover;
        }
        .nav{
          width: 100%;
          margin-top: 15px;
          display:  flex;
          justify-content: space-between;
          .left-icon{
            font-size: 14px;
            color: var(--navCircle);
            i{
              color: #fc476d;
            }
          }
        }
        .nav-content{
          font-size: 14px;
          margin-top: 10px;
          color: var(--colorTip);
        }
        .btn{
          width: 100%;
          height: 40px;
          display: flex;
          justify-content: center;
          margin-top: 18px;
          align-items: center;
          border: 1px solid var(--switchBorder);
          color: var(--activeColor);
        }
      }
      .box-item-length{
        width: 49%;
        margin: 10px 0;
        min-height: 150px;
        padding: 10px;
        background: var(--itemBgk);
        box-sizing: border-box;
        display: flex;
        justify-content: space-between;
        box-shadow: rgba(149, 157, 165, 0.2) 0px 8px 24px;
        .img-left{
          width: 220px;
          height: 250px;
          object-fit: cover;
        }
        .right-box{
          width: calc(100% - 220px);
          margin-left: 15px;
          padding-top: 20px;
          box-sizing: border-box;
          .titles{
            font-weight: 600;
            font-size: 18px;
            color: var(--colorTip);
          }
          .time{
            font-size: 14px;
            color: var(--colorTip);
            margin-top: 10px;
          }
          .btn-bot{
            margin-top: 20px;
            width: 200px;
            height: 42px;
            border-radius: 5px;
            background: var(--activeColor);
            color: var(--navBgk);
            font-size: 14px;
            display: flex;
            justify-content: center;
            align-items: center;
          }
        }
      }
      .box-item-length:hover{
        .right-box{
          .titles{
            color: #fc476d;
          }
        }
      }
    }
    .box-bottom{
      width: 100%;
      display: flex;
      justify-content: center;
      margin-top: 30px;
    }
  }
}

.dialog{
  width: 100%;
  min-height: 400px;
  position: relative;
  display: flex;
  justify-content: space-between;
  .dialog-left{
    width: 400px;
    min-height: 400px;
    img{
      width: 400px;
      height: 600px;
      object-fit: cover;
    }
  }
  .dilog-right{
    width: 450px;
    border-left: 1px solid #f6f6f6;
    padding-left: 20px;
    box-sizing: border-box;
    .title{
      font-size: 18px;
      margin-top: 30px;
      color: #000;
    }
    .time{
      font-size: 12px;
      color: #999;
      margin-top: 10px;
    }
    .content{
      width: 100%;
      min-height: 50px;
      overflow-y: scroll;
      max-height: 200px;
      margin-top: 10px;
    }
    .content::-webkit-scrollbar{
      display: none;
    }
    .comment{
      width: 100%;
      //background: red;
      border-top: 1px solid #f2f2f2;
      margin-top: 20px;
      padding-top: 10px;
      height: 250px;
      overflow-y: scroll;
      .item-nav-comment{
        width: 100%;
        .item-comment{
          width: 100%;
          display: flex;
          margin-bottom: 10px;
          .avatar{
            height: 30px;
            border-radius: 50%;
            width: 30px;
            object-fit: contain;
          }
          .right-box{
            margin-left: 10px;
            p:nth-child(1){
              font-size: 14px;
              color: rgba(168,168,168);
            }
            p:nth-child(2){
              min-height: 30px;
              font-size: 14px;
              color:#000;
            }
          }
        }
        .children{
          width: 100%;
              padding-left: 30px;
          box-sizing: border-box;
          .item-comment{
            width: 100%;
            display: flex;
            margin-bottom: 10px;
            .avatar{
              height: 30px;
              border-radius: 50%;
              width: 30px;
              object-fit: contain;
            }
            .right-box{
              margin-left: 10px;
              p:nth-child(1){
                font-size: 14px;
                color: rgba(168,168,168);
              }
              p:nth-child(2){
                min-height: 30px;
                font-size: 14px;
                color:#000;
              }
            }
          }
        }
      }


    }
    .comment::-webkit-scrollbar{
      display: none;
    }
    .input{
      width: 430px;
      height: 60px;
      //position: absolute;
      bottom: 0;
      //background: red;
      border-top: 1px solid #f6f6f6;
      padding-top: 15px;
      display: flex;
      align-items: center;
      input{
        height: 40px;
        width: 280px;
        background: rgba(248,248,248);
        border-radius: 30px;
        text-indent: 20px;
      }
      input::placeholder{
        color: #999;
      }
      .btn{
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100px;
        height: 40px;
        margin-left: 10px;
        border-radius: 40px;
        background: #fc476d;
        color: #fff;
      }
    }
  }
}
</style>
